/*
 *  Copyright [2012] Paulo de Tarso
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package revendedora.entidades;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.List;
import java.util.Objects;
import javax.persistence.*;


/**
 *
 * @author Tarso
 */
@Entity
@Table(name="TB_CLIENTE",schema="REVENDAAVON")
public class Cliente implements Serializable, Comparable<Cliente> {

    @Id @GeneratedValue(strategy= GenerationType.IDENTITY)
    @Column(name="ID")
    private Long id;
    
    @Column(name="NOME", length=70, nullable=false)
    private String nome;
    
    @Column(name="REFERENCIA", length=255, nullable=true)
    private String referencia;
    
    @Column(name="SALDO_CAMPANHA", scale=2, precision=17, nullable=true)
    private BigDecimal saldoCampanha;
    
    @Column(name="EMAIL", length=50, nullable=true)
    private String email;
    
    @Column(name="TELEFONE", length=9, nullable=true)
    private String telefone;
    
    @OneToMany
    @JoinTable(name="TB_CLIENTE_ITEM_CAMPANHA", 
            joinColumns=@JoinColumn(name="CLIENTE_ID", referencedColumnName="ID"), 
            inverseJoinColumns=@JoinColumn(name="ITEM_ID", referencedColumnName="ID")) 
    private List<ItemCampanha> itensDoCliente;

    public Cliente() {
        this(0l, null, null, null, null, null);
    }

    public Cliente(Long id, String nome, String referencia, BigDecimal saldoCampanha, String email, String telefone) {
        this.id = id;
        this.nome = nome;
        this.referencia = referencia;
        this.saldoCampanha = saldoCampanha;
        this.email = email;
        this.telefone = telefone;
    }
    
    @Override
    public int compareTo(Cliente o) {
        return this.compareTo(o);
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Cliente other = (Cliente) obj;
        if (!Objects.equals(this.id, other.id)) {
            return false;
        }
        if (!Objects.equals(this.nome, other.nome)) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 3;
        hash = 37 * hash + Objects.hashCode(this.id);
        hash = 37 * hash + Objects.hashCode(this.nome);
        return hash;
    }

    @Override
    public String toString() {
        return "Cliente{" + "id=" + id + ", nome=" + nome + ", referencia=" + referencia + ", saldoCampanha=" + saldoCampanha + ", email=" + email + ", telefone=" + telefone + '}';
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getNome() {
        return nome;
    }

    public void setNome(String nome) {
        this.nome = nome;
    }

    public String getReferencia() {
        return referencia;
    }

    public void setReferencia(String referencia) {
        this.referencia = referencia;
    }

    public BigDecimal getSaldoCampanha() {
        return saldoCampanha;
    }

    public void setSaldoCampanha(BigDecimal saldoCampanha) {
        this.saldoCampanha = saldoCampanha;
    }

    public String getTelefone() {
        return telefone;
    }

    public void setTelefone(String telefone) {
        this.telefone = telefone;
    }
}
